package com.yzs.core.base

import androidx.lifecycle.LiveData
import com.yzs.base.base.BaseActivity
import com.yzs.core.bean.NetworkViewState
import com.yzs.core.bean.PageStatus

/**
 *    author : yzs
 *    date   : 2022/1/1316:03
 *    desc   : 业务层的 activity 基类
 */
abstract class CoreBaseActivity : BaseActivity() {

    /**
     * 在基类统一处理加载框
     * 如果不需要统一处理，可以重写该方法 不调用 super
     */
    open fun setPageStateLoadingUI(viewStates: LiveData<NetworkViewState>) {
        viewStates.observeKtNoNull {
            when (it.pageStatus) {
                is PageStatus.LOADING -> showLoadingDialog()
                is PageStatus.SUCCESS -> dismissLoadingDialog()
                is PageStatus.FAILURE -> dismissLoadingDialog()
            }
        }
    }

}